//Sat 19 Dec 2009 11:02:46 PM CST 
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class CountExpressions
{
public:
	int calcExpressions(int x, int y, int val)
	{
		xx = x;
		yy = y;
		value = val;
		return recursive(1, 0, xx) + recursive(0, 1, yy);
	}
	int recursive(int numx, int numy, int res)
	{
		if(numx==2 && numy==2) return (res==value?1:0);
		int ret = 0;
		if(numx < 2) ret += recursive(numx+1, numy, res+xx) + recursive(numx+1, numy, res-xx) + recursive(numx+1, numy, res*xx);
		if(numy < 2) ret += recursive(numx, numy+1, res+yy) + recursive(numx, numy+1, res-yy) + recursive(numx, numy+1, res*yy);
		return ret;
	}
	int xx;
	int yy;
	int value;
};
